<?php
namespace Admin\Model;
use Think\Model;

class AdminModel extends Model
{
	protected $_validate = array(
		array('admin_name','require','用户名必须！'),
		array('admin_name', '', '该用户名已存在', self::EXISTS_VALIDATE, 'unique'),
		array('admin_password', 'require', '密码必须', self::VALUE_VALIDATE),
		array('admin_password2', 'require', '确认密码必须', self::VALUE_VALIDATE),
		array('admin_password', 'admin_password2', '两次输入密码不同', self::VALUE_VALIDATE, 'confirm'),
		array('admin_password', 'checkPassword', '密码格式不正确', self::VALUE_VALIDATE, 'callback'),
	); 
    
    /* 自动完成规则 */
    protected $_auto = array(
		array('admin_password', 'password', self::MODEL_INSERT, 'callback'),
    	array('create_time', "time", self::MODEL_INSERT, 'function'),
        array('update_time', "time", self::MODEL_BOTH, 'function'),
    );

	//验证密码
	public function checkPassword($password) {
		if ($this->isPassword($password)) {
			return true;	
		} else {
			return false;	
		}
	}
	
	public function isPassword($password) {
		$len = strlen($password);
		if ($len >= 6 && $len <= 20) {
			return true;
		} else {
			return false;	
		}
	}
	
	public function password($password) {
		return md5($password);	
	}
}